const { Controller } = require('egg')
const dayjs = require('dayjs')

class ApiController extends Controller {
  /**
   * @api {get} /place/type/scan [场所] 分类扫码数据
   * @apiGroup Place
   * @apiDescription 态势总览-辖区重要场所出入频率分析
   * 
   * @apiParam {String} [scope=day] 范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
          {
              "value": 1222, // 扫码次数
              "label": "机关企事业单位",
          },
          {
              "value": 834,
              "label": "商超",
          }
      ]
  }
   */
  async placeTypeScan() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'

    const returnData = await this.service.trackData.getData(`${scope}_place_type_scan`)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /place/type [场所] 分类数量
   * @apiGroup Place
   * @apiDescription 态势总览-重点场所监控
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
          {
              "value": 8,  // 场所分类个数
              "label": "公共服务、宗教场所"
          },
          {
              "value": 5,
              "label": "机关企事业单位"
          },
      ]
  }
   */
  async placeType() {
    const { ctx } = this
    const { query } = ctx

    const returnData = await this.service.trackData.getData('place_type')

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /place/scan [场所] 扫码数据
   * @apiGroup Place
   * @apiDescription 场所码管理-重点场所码扫码情况
   * 
   * @apiParam {String} [scope=day] 范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
        {
            "total": 27, // 扫码量
            "redCode": 0, // 红码
            "yellowCode": 0, // 黄码
            "greenCode": 0, // 绿码
            "label": "场所名称", // 场所名称
            "placeType": 2, // 场所分类ID
            "placeTypeName": "商业、酒店、餐饮" // 场所分类名称
        },
      ]
  }
   */
  async placeScan() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'

    const returnData = await this.service.trackData.getData(`${scope}_place_scan`)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /place/scan/age-group [场所] 扫码年龄段
   * @apiGroup Place
   * @apiDescription 场所码管理-重点场所码扫码情况
   * 
   * @apiParam {String} [scope=day] 范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
    {
        "code": 0,
        "msg": "success",
        "data": [
            {
                "label": "0-20岁",
                "value": 4
            },
            {
                "label": "20-40岁",
                "value": 19
            },
            {
                "label": "40-60岁",
                "value": 9
            },
            {
                "label": "60岁以上",
                "value": 2
            }
        ]
    }
   */
  async placeScanAgeGroup() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'

    const returnData = await this.service.trackData.getData(`${scope}_place_scan_age_group`)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }
}

module.exports = ApiController
